﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace AutoNumberPlugin
{
    /// <summary>
    /// Helper class for plugin configuration
    /// </summary>
    public class PluginConfiguration
    {
        XmlDocument configDocument;

        /// <summary>
        /// Default constructor
        /// </summary>
        public PluginConfiguration(string config)
        {
            configDocument = new XmlDocument();

            if (!string.IsNullOrEmpty(config))
            {
                configDocument.InnerXml = config;
            }
        }

        /// <summary>
        /// Return value for specified key.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string GetValueNode(string key)
        {
            string valueWithKey = string.Empty;

            XmlNode node = configDocument.SelectSingleNode(String.Format("Settings/setting[@name='{0}']", key));

            if (node != null)
            {
                valueWithKey = node.SelectSingleNode("value").InnerText;
            }

            return valueWithKey;
        }
    }
}
